package com.boarsoft.boar.admin.action;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.boarsoft.bean.ReplyInfo;
import com.boarsoft.boar.admin.CorpBiz;
import com.boarsoft.boar.dir.action.TreeAction;
import com.boarsoft.boar.entity.DirInfo;
import com.boarsoft.common.Authorized;
import com.boarsoft.common.Util;

@Component
@RestController
@RequestMapping("/corp")
public class CorpAction extends TreeAction {
	@Autowired
	protected CorpBiz corpBiz;
	
	@RequestMapping("/save.do")
	@Authorized(code = "corp.save")
	public ReplyInfo<Object> save(DirInfo d) {
		if (Util.strIsEmpty(d.getId())) {
			return this.add(d);
		}
		return this.update(d);
	}

	@RequestMapping("/add.do")
	@Authorized(code = "corp.add")
	public ReplyInfo<Object> add(DirInfo d) {
		d.setType(DirInfo.TYPE_COMPANY);
		return super.add(d);
	}

	/**
	 * 仅当不使用树来管理时使用
	 * 
	 * @return
	 */
	@RequestMapping("/delete.do")
	@Authorized(code = "corp.delete")
	public ReplyInfo<Object> delete(String id) {
		corpBiz.delete(id);
		return ReplyInfo.SUCCESS;
	}
}